<?php
	session_start();
	require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Service/ScheduleService.php';
	require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Service/EmailService.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Context/BaseContext.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/ServiceResult/ServiceResult.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Util/Tool.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../_config/setting/SMTPConfig.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../_config/setting/global.setting.php';
    $scheduleService = new ScheduleService(); 
    $host = Tool::decode($smtp['host'], "sTunnInVietnAm@2012#");
    $port = Tool::decode($smtp['port'], "sTunnInVietnAm@2012#");
    $user = Tool::decode($smtp['user'], "sTunnInVietnAm@2012#");
    $pass = Tool::decode($smtp['pass'], "sTunnInVietnAm@2012#"); 
 	$emailService = new EmailService($host, $port, $user, $pass);
    $scheduleService = new ScheduleService(); 
    $context = new BaseContext();
	$result = new ServiceResult();
	$date = date('Y-m-d');
	$time = date('H:i');	
	$scheduleArr = $scheduleService->getScheduleByStatusByCollectionDate($context, $result,1, $date, $time,0,10);
	$count=$scheduleService->countScheduleByStatusByCollectionDate($context, $result, 1, $date, $time);
	?>
	<span class="mws-dropdown-notif"><?php echo $count?></span>
	 <div class="mws-dropdown-box">
                	<div class="mws-dropdown-content">
                        <ul class="mws-notifications">
							<?php
							if(count($scheduleArr)!=0)
							{
							foreach ($scheduleArr as $schedule) {
								if($schedule->getScheduleDomain()->getIsSent()==1)
								{
									$emailService->sendEmailDeliveryNotification($context, $result, $glb['contactEmail'], $schedule);
									$scheduleService->updateIsSent($context, $result, $schedule->getScheduleDomain()->getScheduleID(), 2);
								}
							?>
							<li class="read">
								<a href="index.php?func=schedule&opt=viewCollectionSchedule&scheduleID=<?php echo $schedule->getScheduleDomain()->getScheduleID(); ?>">
									<span class="message">
									DO/WO: <?php echo $schedule->getScheduleDomain()->getDwoNumber()." - ".$schedule->getMemberDomain()->getPIC();?>
									</span>
									<span class="time">
									Collection: <?php 
													echo $schedule->getScheduleDomain()->getCollectionDate();
													if($schedule->getScheduleDomain()->getCollectionTime() != "00:00:00")
														echo " ".Tool::convert24hTo12h($schedule->getScheduleDomain()->getCollectionTime());
												?>
									</span>
								</a>
							</li>
						
						<?php }}?>
						</ul>
                  		<div class="mws-dropdown-viewall"><a href="index.php?func=schedule&opt=listAlertCollection">View All Notifications</a></div>
    				</div>
     			</div>